package com.jt.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.jt.pojo.Item;
import com.jt.pojo.ItemDesc;
import com.jt.service.DubboItemService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author 张琪
 * @date 2020/12/16
 * @describe
 */
@Controller
@RequestMapping("/items")
public class ItemController {

    @Reference(check = false)           // 启动时, 是否校验有服务的提供者
    private DubboItemService itemService;

    /**
     * 需求分析:
     * 1. 当用户点击商品按钮时, 跳转到商品的展现页面
     * 2. 根据itemId号, 查询item表和itemdesc表
     * 3. 页面展示
     *
     * @param aaa
     * @return
     */

    @RequestMapping("/{itemId}")
    public String findItemById(@PathVariable Long itemId, Model model) {
        Item item = itemService.findItemById(itemId);
        ItemDesc itemDesc = itemService.fiindItemDescById(itemId);

        model.addAttribute("item", item);
        model.addAttribute("itemDesc", itemDesc);
        return "item";
    }

}
